package bdd.beans;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import bdd.beans.DBLink;
import bdd.beans.Examen;

/**
 *
 * @author sojousse
 */
public class ListeExamenEns {
    private DBLink dblink;
     List<Examen> listeExamenEns;

     public ListeExamenEns()
     {
         dblink = new DBLink();
         listeExamenEns = new ArrayList<Examen>();
     }

     public ListeExamenEns(List<Examen> listeExamenEns)
     {
         dblink = new DBLink();
         this.listeExamenEns = listeExamenEns;
     }

    public List<Examen> getListeExamenEns()
    {
        return this.listeExamenEns;
    }

    public void setListeExamenEns(List<Examen> listeExamenEns)
    {
        this.listeExamenEns=listeExamenEns;
    }

    public void add(Examen examen)
    {
        this.listeExamenEns.add(examen);
    }

    public void recupererListeExamenEns(int numEC, int promotion, int enseignant){
      try
      {
            DBLink db = new DBLink();
            db.connexion();
            String rq = "select distinct libelle, examen.numexamen "
                    + "from JNTEXAMENPROMOTIONEC, CRENEAU, EXAMEN "
                    + "where creneau.numec=JNTEXAMENPROMOTIONEC.NUMEC and "
                    + "JNTEXAMENPROMOTIONEC.NUMEXAMEN=EXAMEN.NUMEXAMEN and "
                    + "creneau.numenseignant=" + enseignant
                    + " and creneau.numec=" + numEC
                    + " and creneau.numpromotion=" + promotion;

            PreparedStatement pst = db.getConnection().prepareStatement(rq);
            System.out.println(rq);
            Examen e = new Examen();
            db.setPst(pst);
            ResultSet rs = db.getPst().executeQuery();
            db.setRs(rs);

            while(db.getRs().next())
            {
                e=new Examen();
                e.setLibelle(db.getRs().getString("libelle"));
                e.setNumexamen(db.getRs().getInt("numexamen"));
                
                this.listeExamenEns.add(e);
            }
            db.getConnection().close();
      }
      catch (SQLException ex)
      {
            Logger.getLogger(ListeECEns.class.getName()).log(Level.SEVERE, null, ex);
      }
  }

}
